package com.wn.handler;

import com.wn.entity.CarType;
import com.wn.mapper.CarTypeMapper;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * XxlJob开发示例（shareding模式）
 */
@Component
public class HandlerShardXxlJob {

    private static Logger logger = LoggerFactory.getLogger(HandlerShardXxlJob.class);

    @Autowired
    private CarTypeMapper carTypeMapper;

    /**
     * 2、分片广播任务
     */
    @XxlJob("shardingJobHandler")
    public void shardingJobHandler() throws Exception {
        // 分片参数
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();

        XxlJobHelper.log("分片参数：当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);

        //操作数据
        List<CarType> data = carTypeMapper.findData(shardTotal, shardIndex);
        System.out.println("data = " + data);

    }

}
